/**
* Description: 头部
*
* Created by hrx on 2023/9/18
*/
<template>
  <div class="home-header">
    <el-row>
      <el-col :span="1">
        <img style="margin-left: 20px" class="home-header-icon" src="../../../public/vite.svg"/>
      </el-col>
      <el-col :span="20">
        <div class="home-header-title">
          {{userInfo.merchantName}} - 手卫生管理系统
        </div>
      </el-col>
      <el-col :span="3">
        <div class="home-header-login-out">
          <el-avatar
            :src="userInfo.workPermitImage"
          />
          <span style="margin-left: 15px">{{userInfo.userName}}</span>
          <div style="margin-left: 10px;cursor: pointer;" @click="loginOut">退出</div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">

import {removeLocal} from "@/utils/local";
import {useRouter} from "vue-router";
import {ElMessage} from "element-plus";
import {onMounted, reactive} from "vue";
import {getUserInfoApi, type userInfoDTO, type authoritiesDTO} from "@/api/login";

const router = useRouter();
const userInfo = reactive<userInfoDTO<authoritiesDTO>>({})

const loginOut = () => {
  removeLocal('token')
  router.push('/login')
  ElMessage.success('退出系统');
}
const getUserInfo = async () => {
  let res = await getUserInfoApi();
  Object.assign(userInfo, res.data.data)
}

onMounted(() => {
  getUserInfo()
})

</script>

<style lang="scss" scoped>
.home-header {
  padding: 10px 0;
  background-color: $theme-background-color;
  color: #FFF;
  .home-header-icon {
    width: 40px;
  }
  .home-header-title {
    height: 40px;
    line-height: 40px;
    text-align: left;
    font-size: 24px;
    font-weight: 700;
  }
  .home-header-login-out {
    display: flex;
    justify-content: center;
    align-items: center;
    //text-align: center;
  }
}
</style>